#define DEBUG
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=100000;

class Tree {
public:
  int n, m, ind[maxn+1], to[2*maxn-1], link[2*maxn-1], up[maxn+1];

  void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
  }

  bool check(int o, int fa, int lim) {
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
        if (!check(to[i], o, lim)) {
          return false;
        }
      }
    }
    int huge=0, hugest=0;
    static int son[maxn+1];
    son[0] = 0;
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
        son[++son[0]] = up[to[i]]+1;
        if (son[son[0]]>=lim) {
          hugest = max(hugest, son[son[0]]);
          huge++;
          son[0]--;
        }
      }
    }
    sort(son+1, son+son[0]+1);

    int i, j, t, mv, minv=0;
    if (son[1]<(lim+1)/2) {
      for (i=1, j=son[0], t=0, mv=0; i<=j; i++) {
        for (; i<j && son[j]+son[i]>=lim; j--, t++) {
          int temp=son[j];
          if (temp>mv) {
            swap(temp, mv);
          }
        }
        if (t) {
          t--;
          mv = t>=1 ? mv : 0;
        } else {
          if (minv) {
            if (huge) {
              huge--;
            } else {
              return false;
            }
          }
          minv = i;
        }
      }
    } else {
      t=son[0], mv=son[son[0]];
    }
    if (fa) {
      if (t%2) {
        if (minv) {
          if (huge) {
            huge--;
          } else {
            return false;
          }
        }
        up[o] = huge>1 ? hugest : mv;
      } else {
        if (huge-bool(minv)>0) {
          up[o] = hugest;
        } else {
          if (minv) {
            up[o] = son[minv];
          }
        }
      }
    } else {
      if (bool(minv)+t%2>huge) {
        return false;
      }
    }
    return true;
  }
};

int main() {
  freopen("deleg.in", "r", stdin);
  freopen("deleg.out", "w", stdout);

  static Tree tree;
  int n;
  scanf("%d", &n);
  for (int i=1; i<n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    tree.addSide(a, b);
    tree.addSide(b, a);
  }

  int ans=0;
  for (int l=1, r=n-1, mid; l<=r; ) {
    mid=(l+r)/2;
    if (tree.check(1, 0, mid)) {
      ans = mid;
      l = mid+1;
    } else {
      r = mid-1;
    }
  }
#ifdef DEBUG
  tree.check(1, 0, 7);
#endif

  printf("%d", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
